package com.leyou.item.service.impl;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.mapper.SpecificationMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.pojo.Specification;
import com.leyou.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gsy
 * @date 2022/4/6
 * @apiNote
 */
@Service
public class SpecificationServiceImpl implements SpecificationService {

    @Autowired
    private SpecGroupMapper groupMapper;
    @Autowired
    private SpecParamMapper paramMapper;
    @Autowired
    private SpecificationMapper  specificationMapper;

    @Override
    public List<SpecGroup> queryGroupsByCid(Long id) {
        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(id);
        return this.groupMapper.select(specGroup);
    }




    /**
     * 根据条件查询规格参数
     * @param gid
     * @return
     */
    /**
     * 根据gid查询规格参数
     * @param gid
     * @return
     */
    public List<SpecParam> queryParams(Long gid, Long cid, Boolean generic, Boolean searching) {
        SpecParam record = new SpecParam();
        record.setGroupId(gid);
        record.setCid(cid);
        record.setGeneric(generic);
        record.setSearching(searching);
        return this.paramMapper.select(record);
    }

    @Override
    public void saveSpecification(SpecGroup specGroup) {
        this.groupMapper.insert(specGroup);
    }

    @Override
    public void deleteSpecification(SpecGroup specGroup) {
        this.groupMapper.delete(specGroup);
    }

    @Override
    public void updateSpecification(SpecGroup specGroup) {
        this.groupMapper.updateByPrimaryKeySelective(specGroup);
    }
}
